<template>

  <!--开始必须新建一个div根目录-->
  <div>
    <p>账户<input type="text" v-model="form.username"></p>
    <p>密码<input type="text" v-model="form.password"></p>
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  name: "log",
  data() {
    return {
      form:{}
    }
  },

  methods: {
    login(){
      this.$axios.post('users/login/',this.form)
      .then(res=>{
        if (res.data.code==200){
          localStorage.setItem('puserid', res.data.puserid)
          alert("登录成功")
          this.$router.push({"path": 'news'})
        }else{
          alert("登录失败")

        }

      })
    }
  },

  computed: {},

  mounted() {

  }
}
</script>

<style scoped>

</style>
